package com.shi.vueblog.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@ConditionalOnExpression("${swagger.enabled:true}")
public class SwaggerConfig {

    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .select()
                //这个包下的类才生成文档
                .apis(RequestHandlerSelectors.basePackage("com.shi.vueblog.controller"))
                //加了ApiOperation注解的类，才生成接口文档
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/project-name");

    }

    private ApiInfo getApiInfo(){
        return new ApiInfoBuilder()
        		 .title("vueblog系统")
                 .description("VueBlog项目后台api接口文档")
                 .version("1.0.0")
                 .description("http://127.0.0.1:8080/")
                 .termsOfServiceUrl("http://www.baidu.com/")
                 .build();
    }


}
